package com.example.test.api.impl;

import com.example.test.User;
import com.example.test.api.UserRest;
import com.example.test.api.UserRpc;
import com.example.test.contract.UserResult;
import com.example.test.service.UserService;
import com.example.test.suppert.base.result.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by lsl on 2021/3/3.
 */
public class UserRpcImpl implements UserRpc {

    @Autowired
    private UserService userService;

    @Override
    public BaseResult<UserResult> queryUser(Long id) {
        List<User> users = userService.queryUser(User.builder().id(id).build());
        User user = users.get(0);

        UserResult userResult = new UserResult();
        userResult.setId(user.getId());
        userResult.setName(user.getName());
        userResult.setPassword(user.getPassword());
        userResult.setAddressCount(user.getAddressCount());
        userResult.setUpdateDate(user.getUpdateDate());
        userResult.setCreateDate(user.getCreateDate());
        return BaseResult.success(userResult);
    }
}
